package company.pingan_F;

import java.util.Scanner;

public class PingAn3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), sum = 0, avg, step = 0;
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            int num = scanner.nextInt();
            sum += num;
            nums[i] = num;
        }
        if (sum % n != 0) {
            System.out.println(-1);
            return;
        }
        avg = sum / n;
        for (int i = 0; i < n; i++) {
            int tmp = nums[i] - avg;
            if ((tmp) % 2 != 0) {
                System.out.println(-1);
                return;
            }
            if (tmp < 0) {
                step += Math.abs(tmp);
            }
        }
        System.out.println(step / 2);
    }
}
